import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;


public class SharedMessageQueue {
	int peerID;
	private BlockingQueue<Message> sharedMsgQueue;
	Object dummyObject;
	
	public SharedMessageQueue(){
		sharedMsgQueue = new LinkedBlockingQueue<Message>();
		dummyObject = new Object();
	}
	
	public boolean isEmpty() {
		synchronized (dummyObject) {
			try{
				return sharedMsgQueue.isEmpty();
			}
			catch (Exception e) {
				e.printStackTrace();
				return false;
			}	
		}
	}
	
	public  Message deQueue(){
		synchronized (dummyObject) {
			try{
				return sharedMsgQueue.remove();
			}
			catch (Exception e) {
				e.printStackTrace();
				return null;
			}	
		}
	}
	
	public boolean enQueue(Message m){
		synchronized (dummyObject) {
			try{
				return sharedMsgQueue.add(m);
			}
			catch (Exception e) {
				System.err.println(" who is null:" );
				e.printStackTrace();
				return false;
			}
		}
		
	}
}
